using UnityEngine;
using System.Collections;

// HOW TO - create a new event and make it function:
//
// 1.add the event as a class here
// 2.create a public property in character state machine
// 3.add event handlers OnEvent += <Handler> or OnEventGlobal += <Global Handler>
// 4.when the event is triggered, check listened first, 
//	 then allocing an arg and call SendGameMessage

public class GameEvent<T> 
{
	public event System.Action<T> OnEvent;
	public static event System.Action<T> OnEventGlobal;

	public bool listened
	{
		get { return OnEvent != null || OnEventGlobal != null; }
	}

	public void SendEventMessage(T message)
	{
		if(OnEvent != null)
			OnEvent(message);
		if(OnEventGlobal != null)
			OnEventGlobal(message);
	}
}


public class SplitGameEvent<T>
{
	public event System.Action<T> OnPostEvent;
	public static event System.Action<T> OnPostEventGlobal;
	public event System.Action<T> OnEvent;
	public static event System.Action<T> OnEventGlobal;

	public SplitGameEvent()
	{

	}

	public bool listened
	{
		get { return OnPostEvent != null || OnPostEventGlobal != null
			|| OnEvent != null || OnEventGlobal != null ; }
	}

	public void SendPostEventMessage(T message)
	{
		if(OnPostEvent != null)
			OnPostEvent(message);
		if(OnPostEventGlobal != null)
			OnPostEventGlobal(message);	
	}

	public void SendEventMessage(T message)
	{
		if(OnEvent != null)
			OnEvent(message);
		if(OnEventGlobal != null)
			OnEventGlobal(message);	
	}
}